package com.jiangyg.mall.authz.enums;

import org.apache.commons.lang.StringUtils;

/**
 * 类描述：客户端类型
 *
 * @author jiangyg
 * @date 2022-09-03
 */
public enum ClientType {

    ADMIN("a", "后端管理"),

    PORTAL("p", "");

    /**
     * 代码
     */
    public final String code;

    /**
     * 名称
     */
    public final String name;

    ClientType(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 功能描述：根据代码判断值
     *
     * @param code 代码
     * @return ResourceType
     */
    public static ClientType decide(String code) {
        for (ClientType type : ClientType.values()) {
            if (StringUtils.equalsIgnoreCase(code, type.code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 功能描述：获取所有的资源类型
     *
     * @return 返回类型数组
     */
    public static String[] AllValues() {
        ClientType[] resources = ClientType.values();
        String[] rs = new String[resources.length];
        for (int i = 0; i < resources.length; i++) {
            rs[i] = resources[i].code;
        }
        return rs;
    }

    @Override
    public String toString() {
        return "ClientType [code=" + this.code + ", name=" + this.name + "]";
    }

}
